package com.ruoyi.tmsdriveracc.controller;

import com.ruoyi.tmsdriveracc.domain.ADriverReceipt;
import com.ruoyi.tmsdriveracc.domain.Receipt;
import com.ruoyi.tmsdriveracc.service.ADriverReceiptService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (ADriverReceipt)表控制层
 *
 * @author 小何
 * @since 2022-04-24 00:20:15
 */
@RestController
@RequestMapping("aDriverReceipt")
public class ADriverReceiptController {
    /**
     * 服务对象
     */
    @Resource
    private ADriverReceiptService aDriverReceiptService;

    /**
     * 分页查询
     *
     * @param aDriverReceipt 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<ADriverReceipt>> queryByPage(ADriverReceipt aDriverReceipt, PageRequest pageRequest) {
        return ResponseEntity.ok(this.aDriverReceiptService.queryByPage(aDriverReceipt, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("/queryById")
    public ResponseEntity<ADriverReceipt> queryById(Receipt receipt) {
        return ResponseEntity.ok(this.aDriverReceiptService.queryById(Integer.valueOf(receipt.getContractId())));
    }

    /**
     * 新增数据
     *
     * @param aDriverReceipt 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ADriverReceipt> add(ADriverReceipt aDriverReceipt) {
        return ResponseEntity.ok(this.aDriverReceiptService.insert(aDriverReceipt));
    }

    /**
     * 编辑数据
     *
     * @param aDriverReceipt 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<ADriverReceipt> edit(ADriverReceipt aDriverReceipt) {
        return ResponseEntity.ok(this.aDriverReceiptService.update(aDriverReceipt));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.aDriverReceiptService.deleteById(id));
    }

}

